<script setup>
import { ref, reactive, getCurrentInstance, onMounted, h } from "vue";
import { goRouter, titleCase } from "@/utils";
import { Loading } from '@element-plus/icons-vue'

const global_API = window.global_API;   // {devUrl, prodUrl}

defineProps({
  list: {
    type: Array,
    default: []
  },
  noMore: {
    type: Boolean,
    default: true
  },
  loading: {
    type: Boolean,
    default: false
  },
})
let emits = defineEmits(['itemClick', 'load'])

let loadScroll = () => {
  emits('load')
}
</script>
<template>
<div class="alarm_scroll" v-infinite-scroll="loadScroll" :infinite-scroll-immediate="false">
  <div class="alarm_item" v-for="item in list" :key="item.id" @click="() => emits('itemClick', item)">
    <div class="alarm_item_title">
      <span>{{ item.alarmName }}</span>
    </div>
    <el-row :gutter="10">
      <el-col :span="6">
        <img class="alarm_item_img" :src=" global_API.devUrl + item.imageUrl" alt="">
      </el-col>
      <el-col :span="18" class="alarm_item_valList">
        <span class="alarm_item_val row_drop">ID：{{ item.taskId }}</span>
        <span class="alarm_item_val row_drop">Algorithm：{{ item.algorithmName }}</span>
        <span class="alarm_item_val row_drop">Camera：{{ item.camera }}</span>
        <span class="alarm_item_val row_drop">Location：{{ item.locaiton }}</span>
        <span class="alarm_item_val row_drop">Time：{{ item.time }}</span>
        <span class="alarm_item_val row_drop" v-show="item.riskScore">Risk score：{{ item.riskScore }}</span>
      </el-col>
    </el-row>
    <div class="alarm_item_line" v-if="item.attribution"></div>
    <div class="flex_row" v-if="item.attribution">
      <div class="type_item" v-for="(_a_value, _a_key) in item.attribution" :key="_a_key">
        <span>{{ titleCase(_a_key) }}</span>
        <span>{{_a_value}}</span>
      </div>
    </div>
  </div>
  <div v-if="loading" class="no_data_loading"> <el-icon style="margin-right: 5px"><Loading /></el-icon>Loading...</div>
  <div v-if="noMore" class="no_data">No more data</div>
</div>
</template>
<style scoped lang="less">
.alarm_scroll{
  height: calc(100% - 60px);
  overflow: auto;
  padding: 15px;
  .no_data_loading{
    display: block;
    text-align: center;
    color: #ffffff;
    margin: 10px 0;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .no_data {
    display: block;
    text-align: center;
    color: #666;
    margin: 10px 0;
  }
  .alarm_item:hover{
    box-shadow: 0px 0px 15px 1px rgb(18 134 234);
    border: 1px solid #54D6FD;
    box-sizing: border-box;
  }
  .alarm_item{
    // background-color: rgba(27, 44, 80, 0.5);
    background-color: rgba(72, 131, 255, 0.1);
    padding: 15px;
    margin-bottom: 10px;
    border: 1px solid transparent;
    color: #D9DBDC;
    .type_item{
      display: flex;
      flex-direction: column;
      width: fit-content;
      font-size: 14px;
      color: #D9DBDC;
      margin-right: 30px;
      span:nth-child(1){
        color: #B2B6B7;
      }
      span:nth-child(2){
        line-height: 2;
      }
    }
    .alarm_item_line{
      width: 100%;
      height: 1px;
      background-color: #435B77;
      margin: 15px 0;
    }
    .alarm_item_valList{
      display: flex;
      flex-flow: row wrap;
      justify-content: space-between;
      .alarm_item_val{
        width: 49%;
      }
    }
    .alarm_item_img{
      width: 100%;
      // width: 173px;
      // height: 97px;
    }
    .alarm_item_title{
      font-size: 20px;
      color: #fff;
      margin-bottom: 15px;
    }
  }
}
</style>